package org.example;

import com.sun.source.tree.ReturnTree;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName: RequestController
 * Package: org.example
 * Description:
 *
 * 使用 HttpServletRequest的对象 来 获取请求数据
 *
 * @Author SherryAn
 * @Create 2025/8/9 12:52
 */

@RestController//表示当前类是一个请求处理类
public class RequestController {

    @RequestMapping("/request")
    public String request(HttpServletRequest request) {
//        1.获取请求方式
        System.out.println("请求方式："+request.getMethod());// GET
//        2.获取请求URL地址
        System.out.println("请求URI地址(不完整)："+request.getRequestURI());// /request
        System.out.println("请求URL地址(完整)："+request.getRequestURL());// http://localhost:8080/request
//        3.获取请求协议
        System.out.println("请求协议："+request.getProtocol());// HTTP/1.1
//        4.获取请求参数-name
        System.out.println("请求参数-name："+request.getParameter("name"));// SherryAn
        System.out.println("请求参数-age："+request.getParameter("age"));// 18
//        5.获取请求头-Accept
        System.out.println("请求头-Accept："+request.getHeader("Accept"));// text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
        return "OK!";

    }

}
